Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard / spatial navigation #524

Merged
merged 8 commits into from
Nov 19, 2023
Merged

Keyboard / spatial navigation #524

merged 8 commits into from
Nov 19, 2023

Conversation

mikke89
Copy link
Owner

@mikke89 mikke89 commented Oct 18, 2023

Continuation of #519, including the work of @gleblebedev (thank you!), which has been partially squashed here.

Here are the new changes in this PR:

  • Changes the navigation algorithm quite a bit.
  • Adds some partially related pre-work.
  • Introduces the nav shorthand property.
  • Adds :focus-visible pseudo class.
  • Makes the invaders sample fully work with keyboard navigation, with :focus-visible to highlight the focus.
  • Adds some visual tests where we can test how the algorithm behaves in different situations.
  • Makes navigation take precedent in select elements, instead one can press space to open its options.
  • Restrains auto navigation to stay within the nearest scroll container.

The algorithm is designed to always pick the nearest intersecting element along a given direction. If it finds none, it will effectively try to select one that may lie outside this intersection area as well. There are different design choices here, I tried to not make something too clever on purpose, it's better that it works predictably for the 95% use case. For other cases it is easier to override it manually.

Currently the nav shorthand is a "box" type shorthand - that is, taking 1 to 4 values and assigns them to the direction up/right/down/left, just like for padding and margin properties. We might want to consider instead to use special keywords like horizontal, vertical, and maybe others.

All feedback is very much welcome. I'll clean up the commits in the end before merging.

@gleblebedev
Copy link
Contributor

Tested it on my branch in rbfx game engine. Seems to work fine.

@mikke89
Copy link
Owner Author

mikke89 commented Nov 19, 2023

Thanks for testing.

I cleaned up the commits a bit, and made some changes so that we now can use nav: horizontal and nav: vertical shorthand values.

@mikke89 mikke89 merged commit f6d2e78 into master Nov 19, 2023
28 checks passed
@mikke89 mikke89 deleted the keyboard_navigation branch November 19, 2023 20:16
@mikke89 mikke89 mentioned this pull request Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants